#include "IntSource.h"
#include <cstdlib>
#include <errno.h>

void IntSource::feedTo(Sink<int> *sink) {
	SinkIntAdapter adapter(sink);
	lineSource->feedTo(&adapter);
}

void SinkIntAdapter::process(StringPiece str) {
    char *end = str.begin() + str.length();
    long res = strtol(str.begin(), &end, 10);
    if(errno != EINVAL)
        m_sink -> process((int)res);
}

const char* SinkIntAdapter::finish() {
	return m_sink->finish();
}

